﻿#region 命名空间
using System.Collections.Generic;
using System.ComponentModel;
#endregion

namespace ContentFactory
{
    /// <summary>
    /// 视图对象。
    /// </summary>
    public abstract class ViewObject : INotifyPropertyChanged
    {
        #region 字段

        static readonly Dictionary<string, PropertyChangedEventArgs> args;

        #endregion

        #region 事件

        /// <summary>
        /// 在更改属性值时发生。
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region 初始化

        /// <summary>
        /// 初始化。
        /// </summary>
        static ViewObject()
        {
            args = new Dictionary<string, PropertyChangedEventArgs>();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 触发 PropertyChanged 事件。
        /// </summary>
        protected void Raise(string propertyName)
        {
            if (PropertyChanged != null)
            {
                if (!args.ContainsKey(propertyName))
                    args.Add(propertyName, new PropertyChangedEventArgs(propertyName));
                PropertyChanged(this, args[propertyName]);
            }
        }

        #endregion
    }
}
